<?php 
$ubigeo = '';
include('../Connections/KRAPPERCON.php');
include ("../Connections/Accesos.php");
?>
    <div>
      <input type="button"  name="btn_npro" id="btn_npro" onclick="nuevoProveedor()" value="Nuevo">&nbsp;
      <input type="button"  name="btn_epro" id="btn_epro" onclick="editProveedor()" value="Editar">&nbsp;
      <input type="button"  name="btn_gpro" id="btn_gpro" onclick="grabarProveedor()" value="Grabar">&nbsp;
      <input type="button"   name="btn_lpro" id="btn_lpro" onclick="listarProveedores()" value="Listado">&nbsp;
</div>
<table width="100%" border="0" cellspacing="0" cellpadding="0" id="tbl_dat_prov">
  <tr>
    <td>Codigo de Acreedor</td>
    <td><input name="t_codprv" type="text" placeholder= '[Autogenerado]' id="t_codprv" size="15" maxlength="10" disabled="disabled" /></td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" checked="checked" name="chk_activo" id="chk_activo" />&nbsp;Proveedor Activo    </td>
    <td>&nbsp;</td>
  </tr>
  <tr>
    <td >Apellidos y Nombres o Raz&oacute;n Social</td>
    <td><input name="t_razsoc" class="clsReq" type="text" id="t_razsoc" size="45" />    </td>
  </tr>
  <tr class="noView">
    <td>Nombres</td>
    <td><input name="t_nompro" class="clsReq" type="text" id="t_nompro" size="40" /></td>
  </tr>
  <tr>
    <td>Tipo Doc.NIF:</td>
    <td>
      <select name="cb_tip_prov" class="clsReq" id="cb_tip_prov">
      	<option value="">Seleccione...</option>
        <option value="00">Otros</option>
        <option value="01" selected="selected">DNI</option>
        <option value="06">RUC</option>
        <option value="04">Carnet Extranjer&iacute;a</option>
        <option value="07">Pasaporte</option>
        <option value="A">C&eacute;dula Diplom&aacute;tica</option>
      </select>   </td>
  </tr>
  <tr>
    <td>Nro.Documento :</td>
    <td><input name="t_nifpro" class="clsReq" type="text" id="t_nifpro" size="20" /></td>
  </tr>

  <tr>
    <td>Direcci&oacute;n Fiscal</td>
    <td><input name="t_dirpro" type="text" class="clsReq" id="t_dirpro" size="50" /></td>
  </tr>

  <tr>
    <td>Nombre Contacto / Cargo Contacto:</td>
    <td><input name="t_nomcon" type="text" id="t_nomcon" size="40" maxlength="50" /></td>
  </tr>
  <tr>
    <td></td>
    <td><input name="t_carcon" type="text" id="t_carcon" size="25" maxlength="25" /></td>
  </tr>
  <tr>
    <td>Ubicacion Geografica</td>
    <td>
    <div><select name="cb_prv_pais">
      <?php 
  include ('../Query_Min/getPaises.php');
  ?>
    </select></div>
    <div id="d_ubiprv" class="noView">
      <?php

?>
    </div></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
  </tr>
</table>
						
                    
<script type="text/javascript">
function editProveedor(){
editProv();
}

function nuevoProveedor(){
$('#tbl_dat_prov input').removeAttr('disabled').val('');
$('#t_codprv').attr('disabled','disabled');
$('#d_ubiprv').loadx('Mantenimientos/UbiGeo/UbigeoDefault.php');
}

function actualizarProveedor(){

}

function grabarProveedor(){
	
	if (!$("#tbl_dat_prov").checkInput()){
	return;
	}

	
	// Actualizar
		sendData('Mantenimientos/Opers/OperProv.php',
		{
			field : '1',
			oper : 'save', 
		t_codprv : GEBI('t_codprv').value,	
		t_nompro : GEBI('t_nompro').value,
		t_razsoc : GEBI('t_razsoc').value,
		t_nifpro : GEBI('t_nifpro').value,
		t_dirpro : GEBI('t_dirpro').value,
		cb_ubigeo : GEBI('cb_ubigeo').value,
		chk_activo : (GEBI('chk_activo').checked==true?1:0),
		t_nomcon : GEBI('t_nomcon').value,
		t_carcon : GEBI('t_carcon').value,
		t_tiponif : GEBI('cb_tip_prov').value,
		t_codpais : GEBI('cb_prv_pais').value
		});
		
}

function listarProveedores(){
	loadPage('Mantenimientos/Listas/LstProveedores.php');
}

function editProv(){
$('#tbl_dat_prov input').removeAttr('disabled');
$('#tbl_dat_prov select').removeAttr('disabled');
$('#t_codprv').attr('disabled','disabled');
}

function noEditProv(){
$('#tbl_dat_prov input').attr('disabled','disabled');
$('#tbl_dat_prov select').attr('disabled','disabled');
}

<?php 
if (isset($_GET['buscod'])) {
$buscod = getGet('buscod');
$sql = 'call sp_selProv('.$buscod.');';
//doEcho($sql);
$res = $mysqli->query($sql);
		if ($res){
		if ($row = $res->fetch_assoc()){
			?>
			GEBI('t_codprv').value = '<?php echo $buscod ?>';
			GEBI('t_nompro').value = '<?php echo $row['ProveedNom'] ?>';
			GEBI('t_razsoc').value = '<?php echo $row['ProveedRaz'] ?>';
			GEBI('t_nifpro').value = '<?php echo $row['ProveedNIF'] ?>';
			GEBI('t_dirpro').value = '<?php echo $row['ProveedDir'] ?>';
			GEBI('t_dirpro').value = '<?php echo $row['ProveedDir'] ?>';
			GEBI('chk_activo').checked = <?php echo $row['ProveedSts'] ?>;
			GEBI('t_nomcon').value = '<?php echo $row['ContactoNom'] ?>';
			GEBI('t_carcon').value = '<?php echo $row['ContactoCar'] ?>';
			GEBI('cb_tip_prov').value = '<?php echo $row['TipoNIF'];?>';
			noEditProv();
			/*
			$('#d_ubiprv').loadx('Mantenimientos/Ubigeo/Ubigeo.php',{ubigeo : '<?php echo $row['UbigeoID'] ?>'},function(){
						noEditProv();
			});
			*/
			<?php 		
		}
		else {
		echo ('showOk("El Codigo de proveedor '.$buscod.' no ha sido registrado");');
		}
		$res->close();
		$mysqli->check_result();
		}
}
else {
?>
			$('#d_ubiprv').loadx('Mantenimientos/Ubigeo/UbigeoDefault.php',{ubigeo : '150101'});
<?php } ?>
</script>
